package com.woniu.rabbit.routing_model.producer;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/routing")
@Api("路由模型")
@Slf4j
public class RouteProducerController {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/route_producer")
    @ApiOperation("路由模式生产者")
    public ResponseEntity routeProducer(String msg) {
        // 1. 发送消息
        log.info("路由模式生产者发送消息：" + msg);
        rabbitTemplate.convertAndSend("routing.exchange", "a", msg+"路由key："+"a");
        rabbitTemplate.convertAndSend("routing.exchange", "b", msg+"路由key："+"b");
        rabbitTemplate.convertAndSend("routing.exchange", "c", msg+"路由key："+"c");
        return ResponseEntity.ok("消息发送成功：" + msg);
    }
}
